<?php
namespace Api\Controller;
use Think\Controller;
class SearchController extends CommonController {
    public function _initialize(){
		
	}
	
	public function typesearch(){
		$subnum = I('get.subnum');
		$typenum = I('get.typenum');
		$keyword = I('get.keyword');
		
		$Ware = M('Ware');
		if( $keyword =='null'){
			$list = $Ware->order('addtime desc')->where("subnum={$subnum} and typenum={$typenum}")->select();
			if( $list == false){
				$this->response( false , 1 , '没有数据' , true);
			}
			
			$this->response( true , 0 , $list , true);
		}
		else{
			$where=NULL;
			if($keyword!=''){
				$where="ware_name like '%{$keyword}%'";
			}//模糊搜索
			$data = $Ware->where($where)->select();
			if( $data == false){
				$this->response( false , 3 , '没有数据' , true);
			}
			
			$this->response( true , 2 , $data , true);
		}
		
	}
	
	public function keysearch(){
		$keyword = I('get.keyword');
		
		if( $keyword == ''){
			$this->response( false , 1 , '没有搜索内容' , true);
		}
		$this->response( true , 0 , $keyword , true);
		
	}
}
